package blogs.eidos.cloud.framework.log.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import net.bigdata.cloud.framework.common.api.HttpCodeEnum;
import net.bigdata.cloud.framework.common.api.Resp;
import net.bigdata.cloud.framework.common.dto.BasePageDto;
import net.bigdata.cloud.framework.common.service.impl.BaseServiceImpl;
import net.bigdata.cloud.framework.log.entity.SysLoginLog;
import net.bigdata.cloud.framework.log.mapper.SysLoginLogMapper;
import net.bigdata.cloud.framework.log.service.SysLoginLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 系统登录日志 服务实现类
 *
 * @author Eidos
 * @since 2020-03-24
 */
@Slf4j
@Service
public class SysLoginLogServiceImpl extends BaseServiceImpl<SysLoginLogMapper, SysLoginLog> implements SysLoginLogService {

    @Autowired
    private SysLoginLogMapper sysLoginLogMapper;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public Resp<IPage<SysLoginLog>> getPage(BasePageDto dto) {
        try {
            Page<SysLoginLog> page = new Page<>(dto.getCurrent(), dto.getPageSize());
            QueryWrapper<SysLoginLog> wrapper = new QueryWrapper<>();
            IPage<SysLoginLog> iPage = sysLoginLogMapper.selectPage(page, wrapper);
            return Resp.success(iPage);
        } catch (Exception e) {
            log.error("服务调用异常：", e);
            return Resp.failed(HttpCodeEnum.INVOKE_FAILURE_ERROR);
        }
    }

}
